package com.android.mios;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import android.os.Bundle;
import android.widget.GridView;
import com.android.mios.adapter.LockGridViewAdapte;
import com.android.mios.intenet.PollLoop;
import com.android.mios.model.Category;
import com.android.mios.model.Device;
import com.android.mios.util.Global;

public class LockControlActivity extends DeviceBaseActivity {
	private GridView mGridView;
	private List<Device> lockOfArray;
	private LockGridViewAdapte mLockGridViewAdapte;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.lock_control_layout);
		initData();
		initView();
	}

	private void initData() {
		lockOfArray = new ArrayList<Device>();
		mLockGridViewAdapte = new LockGridViewAdapte(this, lockOfArray,
				R.layout.gv_lock_control_item);
	}

	private void initView() {
		initGridView();

	}

	private void initGridView() {
		mGridView = (GridView) findViewById(R.id.GV_LockControl);
		mGridView.setAdapter(mLockGridViewAdapte);

	}

	@Override
	protected List<Device> getDeviceList(int serialNumber ,int roomId) {
		Map<String, Device> allDevices = PollLoop.getInstance().getDevices();
		List<Device> devices = Device.findUnHideDevicesByCategory(allDevices,
				Category.DOOR_LOCK);
		if (roomId != -1)// -1 is all room
			devices = Device.findDevicesByRoom(devices,serialNumber, roomId);
		return devices;
	}

	@Override
	protected void updateDevice() {
		lockOfArray.clear();
		lockOfArray.addAll(getDeviceList(Global.getInstance().getSerialNumber(),Global.getInstance().getRoomID()));
		mLockGridViewAdapte.notifyDataSetChanged();

	}

}
